<?php

class dashboardReplaceAdminTask extends sfBaseTask
{
  protected function configure()
  {
    // // add your own arguments here
    // $this->addArguments(array(
    //   new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'),
    // ));

    $this->addOptions(array(
      new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name'),
      new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
      new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
      // add your own options here
    ));

    $this->namespace        = 'dashboard';
    $this->name             = 'replace-admin';
    $this->briefDescription = 'Replace Default admin generator template with new';
    $this->detailedDescription = <<<EOF
The [coupons:update-expired|INFO] task does things.
Call it with:

  [php symfony coupons:update-expired|INFO]
EOF;
  }

  protected function execute($arguments = array(), $options = array())
  {
    // initialize the database connection
    $databaseManager = new sfDatabaseManager($this->configuration);
    $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();

    // add your code here
    
    $source = sfConfig::get('sf_plugins_dir').'/tsAdminDashPlugin/data/generator/sfDoctrineModule/admin';
    $dst = sfConfig::get('sf_data_dir').'/generator/sfDoctrineModule/admin';
    
    system('ln -s '.$source .' '.$dst);
    $this->logSection('Dashboard', 'Template admin was replaced');
  }
}
